package org.thanos.demo.mongo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service("mongoService")
public class MongoServiceImpl implements MongoService {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public void insert() {
        DemoEntity demoEntity = new DemoEntity();
        demoEntity.setName(UUID.randomUUID().toString());
        demoEntity.setTimestamp(System.currentTimeMillis());
        mongoTemplate.save(demoEntity);
    }

    @Override
    public void delete() {
        mongoTemplate.dropCollection(DemoEntity.class);
    }

    @Override
    public List<DemoEntity> findAll() {
        return mongoTemplate.findAll(DemoEntity.class);
    }
}
